<template>
  <div>
    <div class="m-3">
      <el-button @click="del">删除</el-button>
      <el-button @click="save">保存</el-button>
    </div>
    <div class="text-center">
      <el-input v-model="obj.value"></el-input>
    </div>
    <div class="m-3">
      <div :key=index v-for="(item , index) in prove">
        <textarea v-model="item.value " class="w-100" style="rows:10">
        </textarea>
      </div>
    </div>
    <div class="m-3">
      <div :key=index v-for="(item , index) in story" class="d-flex">
        <textarea v-model="item.value " class="w-100" style="rows:10">
        </textarea>
      </div>
    </div>
  </div>
</template>

<script>
import {ADD_PROVE, ADD_STORY} from "@/views/tree/index";
import {ProveApi, StoryApi} from "@/api/api";
import {deleteJson, getJson, putJson} from "@/api/http";

export default {
  name: "EditBook",
  data() {
    return {
      ADD_STORY: ADD_STORY,
      ADD_PROVE: ADD_PROVE,
      obj: {
        value: "希洛之书",
      },
      prove: [],
      story: [],
      id: this.$route.query.id,
    }
  },
  methods: {
    async get_data() {
      let res1 = await getJson(ProveApi + "/" +  this.id, {});
      let res2 = await getJson(ProveApi + "/" +  0, {"parent_id": this.id});
      let res3 = await getJson(StoryApi + "/" +  0, {"parent_id": this.id});

      if (res1.code === 1) {
        this.obj = res1.data
      } else {
        this.$message.error('失败');
      }
      if (res3.code === 1) {
        this.prove = res2.data
      } else {
        this.$message.error('失败');
      }
      if (res3.code === 1) {
        this.story = res3.data
      } else {
        this.$message.error('失败');
      }
    },
    async del() {
      let res1 = await deleteJson(ProveApi+ '/' + this.id, {});
    },
    async save() {
      let res1 = await putJson(ProveApi + '/' + 0, this.prove);
      let res2 = await putJson(StoryApi + '/' + 0, this.story);
      this.$router.back()
    },
  },
  created() {
    this.get_data();
  }
}
</script>

<style scoped>

</style>